﻿using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom.Compiler;
using System.IO;

namespace Compiler
{
    /// <summary>
    /// C# compiler
    /// </summary>
    public class CSharpCompiler : ICompiler
    {
        /// <summary>
        /// Compile C# source code
        /// </summary>
        /// <param name="sourceCode"></param>
        public void Compile(String sourceCode)
        {
            // csharp code provider
            CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");

            // parameters
            CompilerParameters parameters = new CompilerParameters();
            parameters.GenerateExecutable = true;
            parameters.OutputAssembly = Path.GetTempPath() + DateTime.Now.ToLongTimeString() +  ".exe";

            // compile source code
            CompilerResults result = provider.CompileAssemblyFromSource(parameters, sourceCode);

            // error when compiling 
            if(result.Errors.Count > 0)
            {
                // don't care :)
            }
        }
    }
}
